package cn.iocoder.yudao.module.biz.service.emergencyReservePlainDrillRecord;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrillRecord.vo.BizEmergencyReservePlainDrillRecordCreateReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrillRecord.vo.BizEmergencyReservePlainDrillRecordExportReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrillRecord.vo.BizEmergencyReservePlainDrillRecordPageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrillRecord.vo.BizEmergencyReservePlainDrillRecordUpdateReqVO;
import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainDrillRecord.BizEmergencyReservePlainDrillRecordConvert;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainDrillRecord.BizEmergencyReservePlainDrillRecordDO;
import cn.iocoder.yudao.module.biz.dal.mysql.emergencyReservePlainDrillRecord.BizEmergencyReservePlainDrillRecordMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.EMERGENCY_RESERVE_PLAIN_DRILL_RECORD_NOT_EXISTS;

/**
 * 演练记录 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BizEmergencyReservePlainDrillRecordServiceImpl implements BizEmergencyReservePlainDrillRecordService {

    @Resource
    private BizEmergencyReservePlainDrillRecordMapper emergencyReservePlainDrillRecordMapper;

    @Override
    public String createEmergencyReservePlainDrillRecord(BizEmergencyReservePlainDrillRecordCreateReqVO createReqVO) {
        // 插入
        BizEmergencyReservePlainDrillRecordDO emergencyReservePlainDrillRecord = BizEmergencyReservePlainDrillRecordConvert.INSTANCE.convert(createReqVO);
        emergencyReservePlainDrillRecordMapper.insert(emergencyReservePlainDrillRecord);
        // 返回
        return emergencyReservePlainDrillRecord.getId();
    }

    @Override
    public void updateEmergencyReservePlainDrillRecord(BizEmergencyReservePlainDrillRecordUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateEmergencyReservePlainDrillRecordExists(updateReqVO.getId());
        // 更新
        BizEmergencyReservePlainDrillRecordDO updateObj = BizEmergencyReservePlainDrillRecordConvert.INSTANCE.convert(updateReqVO);
        emergencyReservePlainDrillRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteEmergencyReservePlainDrillRecord(String id) {
        // 校验存在
        this.validateEmergencyReservePlainDrillRecordExists(id);
        // 删除
        emergencyReservePlainDrillRecordMapper.deleteById(id);
    }

    private void validateEmergencyReservePlainDrillRecordExists(String id) {
        if (emergencyReservePlainDrillRecordMapper.selectById(id) == null) {
            throw exception(EMERGENCY_RESERVE_PLAIN_DRILL_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public BizEmergencyReservePlainDrillRecordDO getEmergencyReservePlainDrillRecord(String id) {
        return emergencyReservePlainDrillRecordMapper.selectById(id);
    }

    @Override
    public List<BizEmergencyReservePlainDrillRecordDO> getEmergencyReservePlainDrillRecordList(Collection<String> ids) {
        return emergencyReservePlainDrillRecordMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<BizEmergencyReservePlainDrillRecordDO> getEmergencyReservePlainDrillRecordPage(BizEmergencyReservePlainDrillRecordPageReqVO pageReqVO) {
        return emergencyReservePlainDrillRecordMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizEmergencyReservePlainDrillRecordDO> getEmergencyReservePlainDrillRecordList(BizEmergencyReservePlainDrillRecordExportReqVO exportReqVO) {
        return emergencyReservePlainDrillRecordMapper.selectList(exportReqVO);
    }

    @Override
    public List<BizEmergencyReservePlainDrillRecordDO> getEmergencyReservePlainDrillRecordListByReserveId(List<String> reserveIds) {
        return emergencyReservePlainDrillRecordMapper.selectListByIds(reserveIds);
    }

}
